//
//  growthRightVController.m
//  SKaURobot
//
//  Created by cdong on 16/3/1.
//  Copyright © 2016年 cdong. All rights reserved.
//

#import "growthRightVController.h"
#import "growthRightCVCell.h"
#import "UIImageView+WebCache.h"
#import "CollectionHeaderReusableView.h"
#import "growthDetailVController.h"
#import "growthRight2CVCell.h"
#import "growthMorePicDayVController.h"

@interface growthRightVController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>

@property (nonatomic ,strong)UICollectionView *photoCollectionV;

@end

@implementation growthRightVController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self loadphotoCollectionView];
    [self.photoCollectionV registerClass:[growthRightCVCell class] forCellWithReuseIdentifier:@"growthRightCVCell"];
    [self.photoCollectionV registerClass:[growthRight2CVCell class] forCellWithReuseIdentifier:@"growthRight2CVCell"];
    [self.photoCollectionV registerClass:[CollectionHeaderReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"CollectionHeaderReusableView"];
    
    self.photoCollectionV.delegate = self;
    self.photoCollectionV.dataSource = self;
}

- (void)loadphotoCollectionView{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.itemSize = CGSizeMake((self.view.frame.size.width - 4)/4, (self.view.frame.size.width - 4)/4);
    layout.minimumInteritemSpacing = 1;
    layout.minimumLineSpacing = 1;
//    layout.sectionInset = UIEdgeInsetsMake(20, 0, 20, 0);
    layout.headerReferenceSize = CGSizeMake(self.view.frame.size.width, (20+31)*matchH);
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    self.photoCollectionV = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64 - 44*matchH - 1) collectionViewLayout:layout];
    self.photoCollectionV.bounces = NO;
    self.photoCollectionV.showsHorizontalScrollIndicator = NO;
    self.photoCollectionV.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.photoCollectionV];
}

// 分组数
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 4;
}

// 每一组个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 7;
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    
    CollectionHeaderReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"CollectionHeaderReusableView" forIndexPath:indexPath];
    headerView.headerL.text = @"2016年8月4日";
    return headerView;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 6) {
        growthRight2CVCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"growthRight2CVCell" forIndexPath:indexPath];
        cell.imageV.image = [UIImage imageNamed:@"default_pic"];
        [cell.morePicBtn setTitle:@"22>" forState:UIControlStateNormal];
        return cell;
    }else{
        growthRightCVCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"growthRightCVCell" forIndexPath:indexPath];
        cell.selected = NO;
        cell.imageV.image = [UIImage imageNamed:@"default_pic"];
        //    [cell.imageV sd_setImageWithURL:[NSURL URLWithString:@"wifi"] placeholderImage:[UIImage imageNamed:@"default_pic"] completed:nil];
        return cell;
    }
}

// 照片详情/每日更多照片
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 6) {
        growthMorePicDayVController *morePicDay = [[growthMorePicDayVController alloc]init];
        [self.navigationController pushViewController:morePicDay animated:YES];
    }else{
        growthDetailVController *detailVC = [[growthDetailVController alloc]init];
        [self.navigationController pushViewController:detailVC animated:YES];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
